package lanqiao13;

import java.util.Scanner;

public class C {
	private static int N;
	private static long sum = 0;
	private static long a;// GB
	private static long b;// MB
	private static long c;// KB
	private static long d;// B
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		N = scan.nextInt();
		scan.nextLine();
		while (N-- > 0) {
			String[] strs = scan.nextLine().split(" ");
			if (strs[0].equals("int")) {
				sum += strs[1].split(",").length * 4;
			} else if (strs[0].equals("int[]")) {
				for (int i = 2; i < strs.length; i++) {
						int n = strs[i].indexOf(']');
						String s = strs[i].substring(4, n);
						sum += Integer.parseInt(s) * 4;
					}
			} else if (strs[0].equals("long")) {
				sum += strs[1].split(",").length * 8;
			} else if (strs[0].equals("long[]")) {
				for (int i = 2; i < strs.length; i++) {
						int n = strs[i].indexOf(']');
						String s = strs[i].substring(5, n);
						sum += Integer.parseInt(s) * 8;
					}
			} else {
				String[] strs2 = strs[1].split(",");
				for (int i = 0; i < strs2.length; i++) {
					int n = strs2[i].indexOf('=') + 2;
					while (strs2[i].charAt(n++) != '\"') {
						sum++;
					}		
				}	
			}
		}
		scan.close();
		
		d = sum % 1024;
		sum /= 1024;
		c = sum % 1024;
		sum /= 1024;
		b = sum % 1024;
		sum /= 1024;
		a = sum % 1024;
		String res = "";
		if (a != 0) {
			res += "" + a + "GB";
			
		}
		if (b != 0) {
			res += "" + b + "MB";
		}
		if (c != 0) {
			res += "" + c + "KB";
		}
		if (d != 0) {
			res += "" + d + "B";
		}
		
		System.out.println(res);
	}
}

//4
//int a=0,b=0;
//long x=0,y=0;
//String s1="hello",s2="world";
//long[] arr1=new long[100000],arr2=new long[100000];